//
//  MovementReadingMeterVC.swift
//  Employee
//
//  Created by tancheng on 2018/6/25.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import Foundation
import SwiftDate

class MovementReadingMeterVC: SWXCPageViewController {
    
    fileprivate var tabTitles:[String] = []
    
    fileprivate var pageViewControllers:[UIViewController] = []
    
    override func viewDidLoad() {
        configData() //提前配置数据
        super.viewDidLoad()
        configUI()
        
        reloadIndex(index: Date().month - 1)
        
    }
    
    func configData() {
        for _ in 0...11 {
            let vc = ReadingMeterTaskViewController()
            pageViewControllers.append(vc)
        }
    }
    
    func configUI() {
        title = "移动抄表"
        createDateView()
        
        let searchButton = UIButton()
        searchButton.frame = SJApp.bounds(width: 30, height: 44)
        searchButton.addTarget(self, action: #selector(searchAction), for: .touchUpInside)
        searchButton.setImage(UIImage.init(named: "search-icon-blue"), for: .normal)
        searchButton.contentHorizontalAlignment = .right
        let searchItem = UIBarButtonItem(customView: searchButton)
        
        let spaceItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        spaceItem.width = -5
        
        self.navigationItem.rightBarButtonItems = [spaceItem, searchItem]
        
    }
    
    func createDateView() {
        
        let yearLab = UILabel()
        yearLab.text = "\(Date().year)年"
        yearLab.font = GlobalConfig.system16Font
        yearLab.textAlignment = .center
        yearLab.textColor = GlobalConfig.bodyTextColor
        yearLab.frame = CGRectMake(0, 0, 74, 48)
        view.addSubview(yearLab)
        
    }
    
    //
    @objc func searchAction() {
        let vc = ReadingMeterTaskSearchVC()
        navigationController?.pushViewController(vc, animated: true)
    }
    
    //
    //MARK: ui数据配置
    override func tabRect() -> CGRect {
        return CGRect.init(x: 74, y: 0, width: UIScreen.width - 74, height: 48)
    }
    override func titlesForTab() -> [String] {
        return ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
    }
    
    override func tabStyle() -> SWXCTabStyle {
        
        var style = SWXCTabStyle()
        style.isSameWidth = true
        style.defualtWidth = 50.3
        style.nomalTextColor = GlobalConfig.bodyTextColor
        style.selectedTextColor = UIColor.white
        style.lineWidth = 38
        style.lineHeight = 32
        style.lineColor = GlobalConfig.BGSkyBlueColor
        style.padding = 0
        
        return style
    }
    
    override func tabHeight() -> CGFloat {
        return 48
    }
    
    override func startIndex() -> Int {
        return Date().month - 1
    }

    override func pageViewController(index: Int) -> UIViewController {
        return pageViewControllers[index]
    }
   
}



